<?php

namespace App\Http\Middleware;

use Closure,Config;
use App\Services\ApisafeService;

class ApisafeAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        $issafe = ApisafeService::checkApiSafe($request->key,$request->sign,$request->timestamp,$request->token,$request->appid);
        if ($issafe["status"] == "error") return response()->json(['status'=>'error','code'=>'2001','msg'=>$issafe["msg"]]);
        return $next($request);
    }
}
